const API = require('../../pages/api/index')


const {
  get,
  post
} = require('../../request/index');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    titleMsg: "",
    show: false,
    title: "",
    arr: [],
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //	获取所有打开的EventChannel事件
    const eventChannel = this.getOpenerEventChannel();
    // 监听 index页面定义的 toB 事件
    eventChannel.once('eventChannelNextGrid', (res) => {
      console.log(res);
      this.setData({
        arr: res.data,
        title: res.title
      })
    })

  },
  scaner(name) {
    wx.scanCode({
      onlyFromCamera: true,
      success(res) {
        wx.navigateTo({
          url: `/pages/emergencyDrill/sign_in/index?name=${name}`,
        })
      }
    })
  },
  handTimeChang(e) {
    console.log(e.detail);
    if (e.detail.name === "Yl_qd" || e.detail.name === "Yl_gcqr") {
      this.scaner(e.detail.name)
      // 走签到
      return
    }
    if (!Object.prototype.hasOwnProperty.call(e.detail, 'children')) {
      if (e.detail.query) {
        let obj = {
          title: e.detail.meta.title,
          category: e.detail.query
        }
        wx.setStorageSync('obj', JSON.stringify(obj));
        wx.navigateTo({
          url: `${e.detail.component}`,
        })
      } else {
        wx.navigateTo({
          url: `${e.detail.component}?title=${e.detail.meta.title}`,
        })
      }
    } else {
      // console.log(e.detail);
      // this.setData({
      //   arr: e.detail.children,
      //   title: e.detail.meta.title
      // })
      wx.navigateTo({
        url: `/pages/nextGrid/nextGrid`,
        success: (res) => {
          // 发送一个事件
          res.eventChannel.emit('eventChannelNextGrid', { data: e.detail.children, title: e.detail.meta.title })
        }
      })
      // let data = JSON.stringify(e.detail.children);
      // wx.navigateTo({
      //   url: `/pages/nextGrid/nextGrid?data=${data}`,
      // })
    }


    // let {
    //   resourceid,
    //   title,
    //   url
    // } = e.detail


    // let {
    //   userid  
    // } = this.data.prolist
    // if (e.detail.title == '考试管理') {
    //   post('/app/exam/paperMember/getByMemberId', {
    //     memberId: userid
    //   }).then(res => {
    //     console.log(res);
    //     if (res.success) {
    //       wx.navigateTo({
    //         url: url,
    //       })
    //     } else {

    //       this.setData({
    //         titleMsg: res.msg,
    //         show:true
    //       }) 


    //       return
    //     }

    //   })
    // }else{
    //   if (url) {
    //     wx.navigateTo({
    //       url: url,
    //     })
    //   } else {
    //     wx.navigateTo({
    //       url: '/pages/nextGrid/nextGrid?resourceid=' + resourceid + '&title=' + title,
    //     })
    //   }
    // }


  },



})